package org.szy.core.common.service.impl;

import cn.hutool.core.util.ReflectUtil;
import com.mybatisflex.core.BaseMapper;
import com.mybatisflex.solon.service.impl.ServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.szy.core.common.service.BaseService;

import java.io.Serializable;
import java.util.Objects;

/**
 * 继承由 Mybatis-Flex 提供的顶级增强 Service 接口。
 * * 增加一些自定义操作
 *
 * @author 孙志阳
 * @date 2023-06-16
 * @since 1.0.0
 **/
public abstract class BaseServiceImpl<M extends BaseMapper<T>, T> extends ServiceImpl<M, T> implements BaseService<T> {

    protected Logger log = LoggerFactory.getLogger(this.getClass());

    @Override
    public String createNewPids(Serializable pid) {
        if (Objects.equals(pid, 0)) {
            return "0";
        } else {
            T obj = getById(pid, "pids");
            if (obj == null) {
                return pid + "";
            }
            return ReflectUtil.getFieldValue(obj, "pids") + "," + pid;
        }
    }


}
